package com.nhim.cms.domain;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;

/**
 * CustomWidgetInstance entity. @author Huy Lieu Ta
 */
@Entity
@Table(name = "nhim_custom_widget_instance", catalog = "nhim_cms")
public class CustomWidgetInstance implements java.io.Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 8116120350590831758L;
	private Integer id;
	private String name;
	private String description;
	private Integer version;
	private Set<CustomWidgetPropertyValue> customWidgetPropertyValues = new HashSet<CustomWidgetPropertyValue>(0);
	private CustomWidget customWidget;
	
	
	// Constructors

	/** default constructor */
	public CustomWidgetInstance() {
	}

	/** minimal constructor */
	public CustomWidgetInstance(String name) {
		this.name = name;
	
	}

	/** full constructor */
	
	public CustomWidgetInstance(String name, String description, Set<CustomWidgetPropertyValue> customWidgetPropertyValues, CustomWidget customWidget, Integer version)
	{
		this.name = name;
		this.description = description;
		this.customWidgetPropertyValues = customWidgetPropertyValues;
		this.customWidget = customWidget;
		this.version = version;
	}
	
	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	
	@Column(name = "name", nullable = false, length = 100)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Column(name = "description", length = 200)
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "customWidgetInstance")
	public Set<CustomWidgetPropertyValue> getCustomWidgetPropertyValues() {		
		return this.customWidgetPropertyValues;
	}

	public void setCustomWidgetPropertyValues(Set<CustomWidgetPropertyValue> customWidgetPropertyValues) {
		this.customWidgetPropertyValues = customWidgetPropertyValues;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "widget_id")
	public CustomWidget getCustomWidget() {
		return this.customWidget;
	}

	public void setCustomWidget(CustomWidget customWidget) {
		this.customWidget = customWidget;
	}
	
	@Version
	@Column(name = "version")
	public Integer getVersion() {
		return this.version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

}
